package errors

import (
	"fmt"
)

// Option 错误选项
type Option func(e *Error)

// WithError 设置错误
func WithError(err error) Option {
	return func(e *Error) {
		e.error = err
	}
}

// WithCode 设置错误码
func WithCode(code int) Option {
	return func(e *Error) {
		e.Code = code
	}
}

// WithMessage 设置消息
func WithMessage(message string) Option {
	return func(e *Error) {
		e.Message = message
	}
}

// WithMessagef 设置格式化消息
func WithMessagef(format string, args ...interface{}) Option {
	return func(e *Error) {
		e.Message = fmt.Sprintf(format, args...)
	}
}

// EnableStack 使能堆栈
func EnableStack() Option {
	return func(e *Error) {
		e.stack = callers(4)
	}
}

// WithStackSkip 堆栈
func WithStackSkip(skip int) Option {
	return func(e *Error) {
		e.stack = callers(skip)
	}
}

// DisableStack 禁止堆栈
func DisableStack() Option {
	return func(e *Error) {
		e.DisableStack()
	}
}
